<?php 
/**
 * 类型属性控制器
 */
class TypeAttrController extends AuthController{
    /**
     * 
     */
    private $model;
     
	public function __auto(){
	    $this->model = K('Attr');
	} 
	 
    public function index(){
    	$tid = Q('get.tid',0,'intval');
    	//遍历Category所有数据
    	$data = $this->model->where("type_tid={$tid}")->all();
		//分配数据
		$this->assign('data',$data);
		$this->assign('tid',$tid);
        $this->display(); 
		
    }
	
	public function add(){
		$tid = Q('get.tid',0,'intval');
		if(IS_POST){
			if(!$this->model->addDate($tid)){
				$this->error($this->model->error);
			}
			$this->success('添加类型成功', U('index',array('tid'=>$tid)));
		}
	    $this->display();
    }
	
	public function edit(){
		$tid = Q('get.tid',0,'intval');
		$atid = Q('get.atid',0,'intval');
		if(IS_POST){
			if(!$this->model->editDate($atid)){
				$this->error($this->model->error);
			}
			$this->success('修改成功', U('index',array('tid'=>$tid)));
		}
		//获得旧数据
		$oldData = $this->model->where("atid={$atid}")->find();
		$this->assign('oldData',$oldData);
		
	    $this->display();
	}
	
	
	/**
	 * 删除
	 */
	public function del(){
		$tid = Q('get.tid',0,'intval');
	    $atid = Q('get.atid',0,'intval');

		//删除分类
		$this->model->where("atid={$atid}")->delete();
		//1.提示信息 2.跳转地址 3.跳转时间
		$this->success('删除成功',U('index',array('tid'=>$tid)));
	}
	
 }
 
 
 
 
 
 
 
 
 
 
 




 ?>